package cn.doit.day03

import scala.io.Source

/**
 * 需求：到你的mysql数据库里面随便挑选一张表
 * 写一个迭代器，每次返回表里面的一行数据（封装成对象）
 */

object _06_迭代器 {
  def main(args: Array[String]): Unit = {
    val iterator: HeroIterator = new HeroIterator
    while (iterator.hasNext){
      println(iterator.next())
    }
  }
}


class HeroIterator extends Iterator[ScalaHero]{
  private val lines: Iterator[String] = Source.fromFile("data/Hero.txt").getLines()

  override def hasNext: Boolean = lines.hasNext

  override def next(): ScalaHero = {
    val line: String = lines.next()
    val arr: Array[String] = line.split(",")
    val arr2: Array[String] = arr(1).split("_")
    val arr3: Array[String] = arr2(1).split("::")
    ScalaHero(arr(0).toInt,arr2(0),arr3(0).toInt,arr3(1).toInt)
  }
}





case class ScalaHero(id:Int,name:String,power:Int,faceValue:Int)